﻿namespace Web.Control.WWW.Group
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text.RegularExpressions;
    using System.IO;
    using Lx.Web.Common.ControlsUI;
    using Lx.Web.Common.UI;
    using Model.WWW_WWW.Group;
    using BLF.WWW_WWW.Group;
    using System.Collections.Generic;
    using BLF;

    public class Forum : BaseControl
    {

        protected Repeater repTopic;
        protected Repeater repAmem;
        protected Literal lLCount;
        /// <summary>
        /// 组的ID
        /// </summary>
        protected string gid="";
        /// <summary>
        /// 浏览者的会员号
        /// </summary>
        protected string Memberno = "";
        /// <summary>
        /// 最近的帖子列表
        /// </summary>
        protected List<TopicModel> tmList;
        /// <summary>
        /// 组的TAG
        /// </summary>
        protected List<string> tagList;
        /// <summary>
        /// 组的管理员
        /// </summary>
        protected List<MemberModel> amList;
         /// <summary>
        /// 组的详细信息
        /// </summary>
        protected GroupModel gm;
        protected int recordCount=0;
        ArrayList al = new ArrayList();
        /// <summary>
        /// 页
        /// </summary>
        protected int pageIndex = 1;
        /// <summary>
        /// 登陆人名称
        /// </summary>
        protected string NickName = "";
        protected override void OnLoad(EventArgs e)
        {
            int l = 15;
            if (lLCount != null) int.TryParse(lLCount.Text, out l);
            if (!string.IsNullOrEmpty(Request["gid"]) && Request["gid"] != "")
            {
                gid = Request["gid"].ToString();

                if (HttpContext.Current.User.Identity.Name != "")
                {
                    Memberno = HttpContext.Current.User.Identity.Name;
                }
                if (!string.IsNullOrEmpty(Request["p"]) && Request["p"] != "")
                {
                    pageIndex = int.Parse(Request["p"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Form["Rety"]) && Request.Form["Rety"] == "join")
                {
                    al = BLF.WWW_WWW.Group.Group.GetAGroupDiscussions(Int64.Parse(gid), Memberno, pageIndex, l, "1");
                }
                else
                {
                    al = BLF.WWW_WWW.Group.Group.GetAGroupDiscussions(Int64.Parse(gid), Memberno, pageIndex, l);
                }
                gm = al[0] as GroupModel;
                tagList = al[1] as List<string>;
                amList = al[2] as List<MemberModel>;
                tmList = al[3] as List<TopicModel>;
                recordCount = int.Parse(al[4].ToString());
                NickName = al[4].ToString();
                if (repTopic != null)
                {
                    repTopic.DataSource = tmList;
                    repTopic.DataBind();
                }
                if (repAmem != null)
                {
                    repAmem.DataSource = amList;
                    repAmem.DataBind();
                }
                //标题
                this.DynamicTitle = GetText("GP522", new string[] { gm.Title });
                if (gm.GroupType != "3")
                {
                    this.DynamicKeywords = GetText("GP523", new string[] { BLF.StaticData.GetLanguageText(gm.Language1), BLF.StaticData.GetLanguageText(gm.Language2) });
                }
                else
                {
                    this.DynamicKeywords = GetText("GP562", new string[] { BLF.StaticData.GetLanguageText(gm.Language2) });
                }
                this.DynamicDescription = GetText("GP524", new string[] { gm.Title });
                base.OnLoad(e);
            }
            else
            {
                Response.End();
                return;
            }            
        }

    }
}